#-*-coding:utf8;-*-

from ylTDX2 import * #from ylTDX import all def function
from  _utinity import *


"""
VARC:=LOW;
VARD:=REF(LOW,1);
VARE:=SMA(ABS(VARC-VARD),3,1)/SMA(MAX(VARC-VARD,0),3,1)*100;
VARF:=MA(VARE/10,3);
VAR10:=LLV(LOW,30);
VAR11:=HHV(VARF,30);
主力观望:MA(IF(LOW<=VAR10,(VARF+VAR11*2)/2,0),3);
VAR1B:=REF((LOW+OPEN+CLOSE+HIGH)/4,1);
VAR2B:=SMA(ABS(LOW-VAR1B),13,1)/SMA(MAX(LOW-VAR1B,0),10,1);
VAR3B:=EMA(VAR2B,10);
VAR4B:=LLV(LOW,33);
VAR5B:=EMA(IF(LOW<=VAR4B,VAR3B,0),3)*3;
主力进场:IF(VAR5B>REF(VAR5B,1),VAR5B,0),COLORRED,LINETHICK6;
STICKLINE(VAR5B>REF(VAR5B,1),0,VAR5B,3,0 ),COLORRED;
洗盘:IF(VAR5B<REF(VAR5B,1),VAR5B,0),COLORGREEN;
VAR1:=REF((LOW+OPEN+CLOSE+HIGH)/4,1);
VAR2:=SMA(ABS(LOW-VAR1),13,1)/SMA(MAX(LOW-VAR1,0),10,1);
VAR3:=EMA(VAR2,10);
VAR4:=LLV(LOW,33);
VAR5:=EMA(IF(LOW<=VAR4,VAR3,0),3);
STICKLINE(VAR5>REF(VAR5,1),0,VAR5,6,0 ),COLORGREEN;
STICKLINE(VAR5<REF(VAR5,1),0,VAR5,6,0),COLORRED;
铁峰参数:VAR5>REF(VAR5,4) {AND C>REF(C,1)},COLORFFFF00;
VAR2C:=(HIGH+LOW+CLOSE*2)/4;
VAR3C:=EMA(VAR2C,7);
VAR4C:=STD(VAR2C,7);
VAR5C:=(VAR2C-VAR3C)*100/VAR4;
VAR6C:=EMA(VAR5C,3);
WW:(EMA(VAR6C,5)+100)/2-3,COLORFF00FF;
MM:HHV(WW,3),COLORFF3333;
AAA=AMOUNT/VOL/100;
"""

def zjjr(code,file_name=None):                      
    df=get_data(code)
    OPEN=tdx(df["Open"].to_list()) #open 是file open
    HIGH=tdx(df["High"].to_list())
    LOW=tdx(df["Low"].to_list())
    CLOSE=tdx(df["Close"].to_list())
    VOL=tdx(df["Volume"].to_list())
    AMOUNT=tdx(df["Amount"].to_list())
    VARC=LOW
    VARD=REF(LOW,1)
    VARE=SMA(ABS(VARC-VARD),3,1)/SMA(MAX(VARC-VARD,0),3,1)*100
    VARF=MA(VARE/10,3)
    VAR10=LLV(LOW,30)
    VAR11=HHV(VARF,30)
    主力观望=MA(IF(LOW<=VAR10,(VARF+VAR11*2)/2,0),3)
    VAR1B=REF((LOW+OPEN+CLOSE+HIGH)/4,1)
    VAR2B=SMA(ABS(LOW-VAR1B),13,1)/SMA(MAX(LOW-VAR1B,0),10,1)
    VAR3B=EMA(VAR2B,10)
    VAR4B=LLV(LOW,33)
    VAR5B=EMA(IF(LOW<=VAR4B,VAR3B,0),3)*3
    主力进场=IF(VAR5B>REF(VAR5B,1),VAR5B,0)
    洗盘=IF(VAR5B<REF(VAR5B,1),VAR5B,0)
    VAR1=REF((LOW+OPEN+CLOSE+HIGH)/4,1)
    VAR2=SMA(ABS(LOW-VAR1),13,1)/SMA(MAX(LOW-VAR1,0),10,1)
    VAR3=EMA(VAR2,10)
    VAR4=LLV(LOW,33)
    VAR5=EMA(IF(LOW<=VAR4,VAR3,0),3)
    铁峰参数=VAR5>REF(VAR5,4)
    VAR2C=(HIGH+LOW+CLOSE*2)/4
    VAR3C=EMA(VAR2C,7)
    VAR4C=STD(VAR2C,7)
    VAR5C=(VAR2C-VAR3C)*100/VAR4
    VAR6C=EMA(VAR5C,3)
    WW=(EMA(VAR6C,5)+100)/2-3
    MM=HHV(WW,3)
    AAA=AMOUNT/VOL/100
    if file_name is not None:
        output_File = open(file_name,'a+') 
        output_File.write('{},{},{}\n'.format(str(code).zfill(6),str(round(主力进场[-1],2)),df['close'][-1]))
        output_File.flush()
        return "%s complete"%str(code).zfill(6)   

if __name__=='__main__':
    sort_stratedy(zjjr,ascending=False)
    # zljc(603698)